home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000…tember: Reference Library / Dev.CD Sep 00 RL Disk 1.toast / mac / Technical Documentation / Develop / develop Issue 28 / develop Issue 28 code / MacApp Debugging / TwistDownLists / UVolume.cp < prev    next >
Encoding:
Text File  |  1996-07-15  |  7.0 KB  |  228 lines  |  [TEXT/MPS ]

  1. //----------------------------------------------------------------------------------------
  2. // UVolume.cp
  3. // ETO20 MacApp 3.3.1, MPW 3.4.1
  4. // Copyright ©1996 Conrad Kopala
  5. // Twist Down Lists version 2.0a0 7/15/96
  6. //----------------------------------------------------------------------------------------
  7.  
  8. #ifndef __UVOLUME__
  9. #include "UVolume.h"
  10. #endif
  11.  
  12. #ifndef __UTWISTDOWNGLOBALS__
  13. #include "UTwistDownGlobals.h"
  14. #endif
  15.  
  16. // MacApp
  17. //None
  18.  
  19. // Toolbox
  20. //None
  21.  
  22. // ANSI
  23. //None
  24. //========================================================================================
  25. // GLOBAL Procedures
  26. //========================================================================================
  27. #undef Inherited
  28.  
  29. //----------------------------------------------------------------------------------------
  30. // NewVolume: 
  31. //----------------------------------------------------------------------------------------
  32. #pragma segment MAFileOpen
  33.  
  34. TVolume* NewVolume(OSType itsCreator)
  35. {
  36.     TVolume * theVolume;
  37.  
  38.     theVolume = new TVolume;
  39.     theVolume -> IVolume(itsCreator);
  40.     return theVolume;
  41. }
  42. //========================================================================================
  43. // CLASS TVolume
  44. //========================================================================================
  45. #undef Inherited
  46. #define Inherited TObject
  47.  
  48. #pragma segment MAFileOpen
  49. MA_DEFINE_CLASS_M1(TVolume, Inherited);
  50.  
  51. //----------------------------------------------------------------------------------------
  52. // TVolume constructor    
  53. //----------------------------------------------------------------------------------------
  54. #pragma segment MAFileOpen
  55. TVolume::TVolume()
  56. {
  57. fFileSpec.vRefNum = 0;
  58. fFileSpec.parID = 0;
  59. fFileSpec.name[0] = '\0';
  60.  
  61. fFileType = 'disk';
  62. fCreator = '\?\?\?\?';
  63.  
  64. #if qDebug
  65. this -> PrintAppConstructorClassInfo();
  66. #endif
  67. }
  68. //----------------------------------------------------------------------------------------
  69. // TVolume::IVolume: 
  70. //----------------------------------------------------------------------------------------
  71. #pragma segment MAFileOpen
  72. void TVolume::IVolume(OSType itsCreator)
  73. {
  74. this -> IObject();
  75.  
  76. fCreator = itsCreator;
  77.  
  78. }
  79. //----------------------------------------------------------------------------------------
  80. // TVolume destructor    
  81. //----------------------------------------------------------------------------------------
  82. #pragma segment MAFileClose
  83. TVolume::~TVolume()
  84. {
  85. #if qDebug
  86. this -> PrintAppDestructorClassInfo();
  87. #endif
  88. //----------------------------------------------------------------------------------------
  89. // TVolume::IsHFSVolume: 
  90. //----------------------------------------------------------------------------------------
  91. #pragma segment MAFileNonRes
  92. Boolean TVolume::IsHFSVolume()
  93. {
  94. Boolean result = FALSE;
  95. HVolumeParam pb;
  96.  
  97. BlockSet((Ptr) & pb, sizeof(HVolumeParam), 0x00);
  98.  
  99. pb.ioVRefNum = this -> GetVolRefNum();;
  100. pb.ioVolIndex = 0;
  101.  
  102. FailOSErr(PBHGetVInfoSync((HParmBlkPtr)&pb));
  103.         
  104. short volType = pb.ioVSigWord;
  105.  
  106. if (volType == 0x4244)
  107.     result = TRUE;
  108.  
  109. return result;    
  110. }
  111. //----------------------------------------------------------------------------------------
  112. // TVolume::Specify: 
  113. //----------------------------------------------------------------------------------------
  114. #pragma segment MAFileNonRes
  115. void TVolume::Specify(const FSSpec& theFile)
  116. {
  117. fFileSpec = theFile;
  118. }
  119. //----------------------------------------------------------------------------------------
  120. // TVolume::SpecifyWithStandardFileReply: 
  121. //----------------------------------------------------------------------------------------
  122. #pragma segment MAFileNonRes
  123. void TVolume::SpecifyWithStandardFileReply(const StandardFileReply& itsReply)
  124. {
  125. this -> Specify(itsReply.sfFile);
  126. }
  127. //----------------------------------------------------------------------------------------
  128. // TVolume::SpecifyWithSFReply: 
  129. //----------------------------------------------------------------------------------------
  130. #pragma segment MAFileNonRes
  131. OSErr TVolume::SpecifyWithSFReply(const SFReply& itsReply)
  132. {
  133.  
  134. OSErr theErr = this -> SpecifyWithTrio(itsReply.vRefNum, 0, itsReply.fName);
  135.     
  136. return theErr;
  137. }
  138. //----------------------------------------------------------------------------------------
  139. // TVolume::SpecifyWithAlias: 
  140. //----------------------------------------------------------------------------------------
  141. #pragma segment MAFileNonRes
  142. OSErr TVolume::SpecifyWithAlias(AliasHandle alias)
  143. {
  144. FSSpec theFileSpec;
  145. Boolean dontCare;
  146.  
  147. OSErr theErr = ResolveAlias((FSSpecPtr)NULL, alias, &theFileSpec, &dontCare);
  148. if (theErr == noErr)
  149.     this -> Specify(theFileSpec);
  150.  
  151. return theErr;
  152. }
  153. //----------------------------------------------------------------------------------------
  154. // TVolume::SpecifyWithTrio: 
  155. //----------------------------------------------------------------------------------------
  156. #pragma segment MAFileNonRes
  157. OSErr TVolume::SpecifyWithTrio(short volRefNum, long dirID, const CStr63& name)
  158. {
  159.     FSSpec theFileSpec;
  160.     OSErr theErr = noErr;
  161.  
  162.     if ((theErr = FSMakeFSSpec(volRefNum, dirID, name, &theFileSpec)) == fnfErr)
  163.         theErr = noErr;                        // The file may not yet exist
  164.  
  165.     if (theErr == noErr)
  166.         this->Specify(theFileSpec);
  167.     return theErr;
  168. }
  169. //----------------------------------------------------------------------------------------
  170. // TVolume::GetAlias: 
  171. //----------------------------------------------------------------------------------------
  172. #pragma segment MAFileNonRes
  173. OSErr TVolume::GetAlias(AliasHandle& alias)
  174. {
  175. FSSpec theFileSpec = fFileSpec;
  176. return NewAliasMinimal(&theFileSpec, &alias);
  177. //----------------------------------------------------------------------------------------
  178. // TVolume::GetCatInfo: 
  179. //----------------------------------------------------------------------------------------
  180. #pragma segment MAFileNonRes
  181. OSErr TVolume::GetCatInfo(CInfoPBRec& cInfo)
  182. {
  183.     CStr63 itsName;
  184.  
  185.     itsName = fFileSpec.name;
  186.     cInfo.hFileInfo.ioNamePtr = (StringPtr) itsName;
  187.     cInfo.hFileInfo.ioVRefNum = fFileSpec.vRefNum;
  188.     cInfo.hFileInfo.ioFDirIndex = 0;
  189.     cInfo.hFileInfo.ioDirID = fFileSpec.parID;
  190.     OSErr err = PBGetCatInfoSync(&cInfo);
  191.     cInfo.hFileInfo.ioNamePtr = NULL;
  192.     return err;
  193. }
  194. //----------------------------------------------------------------------------------------
  195. // TVolume::GetName: 
  196. //----------------------------------------------------------------------------------------
  197. #pragma segment MAFileRes
  198. void TVolume::GetName(CStr31& name)
  199. {
  200.     name = fFileSpec.name;
  201. }
  202. //----------------------------------------------------------------------------------------
  203. // TVolume::GetVolRefNum: 
  204. //----------------------------------------------------------------------------------------
  205. #pragma segment MAFileOpen
  206. short TVolume::GetVolRefNum()
  207. {
  208.     return fFileSpec.vRefNum;
  209. }
  210. //----------------------------------------------------------------------------------------
  211. // TVolume::IsSameVolume: analog of IsSameFile    
  212. //----------------------------------------------------------------------------------------
  213. #pragma segment MAFileOpen
  214. Boolean TVolume::IsSameVolume(TVolume* aVolume)
  215. {
  216.  
  217.     if (fFileSpec.vRefNum == aVolume -> GetVolRefNum())
  218.         {
  219.             CStr31    name;
  220.         
  221.             aVolume -> GetName(name);
  222.             return (EqualString(*((CString *) fFileSpec.name), name, FALSE, TRUE));
  223.         }
  224.     return FALSE;
  225. }
  226. #pragma segment Inline